//请求路径常量
import * as req_con from '../../utils/constant'
//数据
import {tableData} from '../sql_data/data'
export let roleDao = (url,params) => {
    //模仿数据库CRUD操作
    switch (url) {
         //Role
        case req_con.ROLE_CONSTANT.ROLELISTGTE:
            return  findTableData(params)
        case req_con.ROLE_CONSTANT.ROLEADD:
            return  tableDataAdd(params)
        case req_con.ROLE_CONSTANT.ROLEDELETE:
            return  tableDataDelete(params)
        case req_con.ROLE_CONSTANT.ROLEUPDATE:
            return  tableDataUpdate(params)
        default:
            break;
    }
}
//Layout的Role查询表单数据
let findTableData = () => {
    return tableData
}

//Layout的Role添加表单数据
let tableDataAdd = (params) => {
    let index = tableData.length+1
    params.id=index 
    tableData.push(params)
    return {
        success: true,
        message: '添加成功'
    }
}

//Layout的Role删除表单数据
let tableDataDelete = (params) => {
    let index = tableData.findIndex(v=>v.roleName===params.roleName)
    tableData.splice(index,1)
    //重新设置id
    tableData.forEach((v,index)=>{
        v.id=index+1
    })
    return {
        success: true,
        message: '删除成功'
    }
}

//Layout的Role修改表单数据
let tableDataUpdate = (params) => {
    tableData.forEach(v=>{
        if(v.id===params.id){
            v.roleName = params.roleName
        }
    })
    return {
        success: true,
        message: '修改成功'
    }
}
